﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Blazing.WebFacade.Extensions;
using System.Web;

namespace Blazing.Web.Modules
{
    public class Page404Module : System.Web.IHttpModule
    {
        #region IHttpModule Members

        public void Dispose()
        {
            
        }

        public void Init(System.Web.HttpApplication context)
        {
            context.AuthenticateRequest += context_AuthenticateRequest;
        }

        void context_AuthenticateRequest(object sender, EventArgs e)
        {
            HttpApplication app = (HttpApplication)sender;
            string path = app.Context.Request.QueryString["path"];
            if (!string.IsNullOrEmpty(path) && path.EndsWith("/404/"))
            {
                app.Context.RewritePath("~/404.aspx", app.Context.Request.PathInfo, string.Empty);
            }   
        }

        #endregion
    }
}
